<?php
        define("GRID_SOURCE", "");       
        include(GRID_SOURCE."class/gridclasses.php"); //Include the grid engine.
        
        session_start();
        require_once "../funciones.php";
        $grid_id = array("grid");
        unset($_SESSION["grid"]);
        include(GRID_SOURCE."class/gridcreate.php"); //Creates grid objects.
        $taxonomia = $_REQUEST['item'];
        $_SESSION['caweb']['itemeco']= $_REQUEST['item'];
?>
<html>
        <head>
                <title>Entradas por Compras</title>
                <script language="Javascript" type="text/javascript" src="<?php print(GRID_SOURCE);?>javascript/javascript.js"></script>
                <link href="<?php print(GRID_SOURCE);?>css/style.css" rel="stylesheet" type="text/css" />
				<script type='text/javascript' src="<?php print(GRID_SOURCE);?>server.php?client=all"></script>
				<script>
				HTML_AJAX.defaultServerUrl = '<?php print(GRID_SOURCE);?>server.php';
				</script>
		<script src="caweb2.js"></script>
		<script src="jquery.js"></script>
        <script>
        function validar0(e)
        {
            var tecla;
        	
            if (document.all) { tecla = e.keyCode;  } 
            else {  tecla = e.which; }
            if (tecla == 13) { $('#serial').focus();  }
            else { return false; }
        }
        
        function validar1(e) {
                var tecla;
            	
                if (document.all) { tecla = e.keyCode;  } 
                else {  tecla = e.which; }
                if (tecla == 13 && $('#interno').val() != '' && $('#oc').val() != 'XXX' ) {  
                    $('#guardar').attr('disabled','');  
                    $('#interno').focus(); }
                else { return false; }
            }
            
        function validar2(e)
        {
            var tecla;
        	
            if (document.all) { tecla = e.keyCode;  } 
            else {  tecla = e.which; }
            if (tecla == 13) { $('#serial2').focus();  }
            else { return false; }
        }            
        
        function validar3(e)
        {
            var tecla;
        	
            if (document.all) { tecla = e.keyCode;  } 
            else {  tecla = e.which; }
            if (tecla == 13) { $('#relacionado').focus();  }
            else { return false; }
        }
        
        function validar4(e) {
        var tecla;
    	
        if (document.all) { tecla = e.keyCode;  } 
        else {  tecla = e.which; }
        if (tecla == 13 && $('#interno2').val() != '' && $('#oc').val() != 'XXX' ) {  
            $('#guardar2').attr('disabled','');  
            $('#interno2').focus(); }
        else { return false; }
        }
        
		</script>
        </head>
        <body onload="
            $('#cimo').hide();
            $('#prash').hide();
            $('#adita').hide();
            var tipoitem = '<?echo $taxonomia;?>';
            $.post('../scripts/validaItem.php', {item:tipoitem,opc:0}, function(porCantidad){
                if(porCantidad == 'No'){
                    if(tipoitem.charAt(0) == 'C' || tipoitem.charAt(0) == 'I' || tipoitem.charAt(0) == 'M' || tipoitem.charAt(0) == 'O' || tipoitem.charAt(0) == 'P'){
                        $('#cimo').show(); $('#interno').focus();
                    }
                    else
                        $('#adita').show(); $('#interno2').focus();
                }
                else{
                    $('#prash').show(); $('#cantidad').focus(); 
                }
            });
            ">
            <br />
            <div id="cimo">
                <form name="ecocimo" method="POST" action="adiciona_eco.php?op=1">
                    Interno: <input type="text" id="interno" size="30" name="interno" value="" onkeypress="validar0(event);"/>
                    Serial:  <input type="text" id="serial" size="30" name="serial" value="" onkeypress="validar1(event); "/>
                    <input type="hidden" name="item" id="item" value="<? echo $_REQUEST[item]; ?>"/>
                    <input name="guardar" id="guardar" type="submit" value="Adicionar" disabled="disabled"/>
                </form>
            </div>
            <div id="adita">
                <form name="ecoadita" method="POST" action="adiciona_eco.php?op=2">
                    Interno: <input type="text" id="interno2" size="30" name="interno2" value="" onkeypress="validar2(event);"/>
                    Serial:  <input type="text" id="serial2" size="30" name="serial2" value="" onkeypress="validar3(event); "/>
                    Relacionado con:  <input type="text" id="relacionado" size="15" name="relacionado" value="" onkeypress="validar4(event); "/>
                    <input type="hidden" name="item" id="item" value="<? echo $_REQUEST[item]; ?>"/>
                    <input name="guardar2" id="guardar2" type="submit" value="Adicionar" disabled="disabled"/>
                </form>
            </div>
            <div id="prash">
                <form name="ecoprash" method="POST" action="adiciona_eco.php?op=3">
                    Cantidad: <input type="text" id="cantidad" size="30" name="cantidad" value=""/>
                    <input type="hidden" name="item" id="item" value="<? echo $_REQUEST[item]; ?>"/>
                    <input name="guardar3" id="guardar3" type="submit" value="Adicionar" disabled="disabled"/>
                </form>
            </div>
        <?php

			$transaccion=$_SESSION['caweb']['consecutivo'];
		 	if ($_SESSION['caweb']['resultado'] == 1) { echo "<font color=green size=4><b> CORRECTO </b></font>"; }
		 	if ($_SESSION['caweb']['resultado'] == 2) { echo "<font color=orange size=4><b> INTERNO YA ESTA EN INVENTARIO </b></font>"; }
            if ($_SESSION['caweb']['resultado'] == 3) { echo "<font color=orange size=4><b> INTERNO en esta transaccion </b></font>"; }
            
       		$consecutivo=$_SESSION['caweb']['consecutivo'];
			$condicion="transaccion='$consecutivo'";
   			$_SESSION["grid"]->SetDatabaseConnection($_SESSION['caweb']['basededatos'], "caweb", "caweb");

           	$_SESSION["grid"]->SetSqlSelect('id, cantidad, interno, serial, item, relacionado', 'temporal', $condicion);
			$_SESSION["grid"]->SetUniqueDatabaseColumn("id", false);
			$_SESSION["grid"]->SetTitleName("(Transaccion: $transaccion) - Entrada de Equipos por Compras ");
			$_SESSION["grid"]->SetEditModeEdit(true);
			$_SESSION["grid"]->SetMaxRowsEachPage(30);
            $_SESSION["grid"]->SetDatabaseColumnEditable("id", false);
            $_SESSION["grid"]->SetDatabaseColumnEditable("cantidad", true);
			$_SESSION["grid"]->SetDatabaseColumnEditable("interno", false);
            $_SESSION["grid"]->SetDatabaseColumnEditable("serial", true);
   	        $_SESSION["grid"]->SetDatabaseColumnEditable("item", false);
            $_SESSION["grid"]->SetDatabaseColumnEditable("relacionado", true);
			$_SESSION["grid"]->SetShowExcelIco(false);
			$_SESSION["grid"]->SetShowPrintIco(false);
			$_SESSION["grid"]->PrintGrid(MODE_EDIT);
         ?>
        </body> 
</html>